package demo4.controller;

import com.tedu.InputUtil;
import demo4.mapper.IUserMapper;
import demo4.vo.User;
import demo4.vo.UserLoginDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class UserController {
    @Autowired
    private IUserMapper userMapper;
    public void regUser(){
        User user = InputUtil.getInputObject(new User(),"欢迎注册");
        if(userMapper.selectByUsername(user.getUsername())!=null){
            System.out.println("用户名已存在");
        }else{
            System.out.println(userMapper.insert(user)>0?"注册成功":"注册失败");
        }
        System.out.println("UserController:用户注册结束");
    }

    public void login(){
        UserLoginDTO userLoginDTO = InputUtil.getInputObject(new UserLoginDTO(),"欢迎登录");
        System.out.println(userMapper.login(userLoginDTO.getUsername(),userLoginDTO.getPassword())>0?"登录成功":"登录失败");
    }
    public void selectAll(){
        for (User user:userMapper.selectAll()) {
            System.out.println(user);
        }

    }
}
